/**
 * @(#)PeriodicUpdateSender.java
 */

/**
 *  @author Didier Gutacker
 *  @version 1.0
 *  @see Periodic
 *  @see NodeRIP
 *  
 */

class PeriodicUpdateSender extends Periodic {
  NodeRIP parent;  

  PeriodicUpdateSender( NodeRIP parent ) {
    this.parent = parent;
    timer = new Thread( parent.getNet().getThreadGroup(), this );
    timer.setPriority( Thread.MIN_PRIORITY );
    timer.start();
  } // PeriodicUpdateSender.PeriodicUpdateSender

  synchronized public void run() {
    parent.paintRequest();
    for ( ;; ) {
      if ( parent.finished() ) {
	return;
      } // if
      parent.sendUpdatePackets();
      try {
	if ( ! parent.finished() ) {
	  int speed = ((NetworkRIP)parent.getNet()).getSpeed();
	  if ( speed == 1 ) {
	    wait( 60000 );		// about every 30 seconds
	  } else if ( speed == 0 ) {
	    wait( 90000 );
	  } else {
	    wait( 30000 );
	  } // if
	} // if
      } catch( InterruptedException e ) {
      } // try
    } // for
  } // PeriodicUpdateSender.run

} // PeriodicUpdateSender


